package com.cdream.basic.algorithm.leetcode.dp;

import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Set;

/**
 * @author cdream
 * @date 8/9/21
 */
public class Question313 {
    public int nthSuperUglyNumber(int n, int[] primes) {
        PriorityQueue<Long> pq = new PriorityQueue<>();
        Set<Long> used = new HashSet<>();
        pq.offer(1L);
        used.add(1L);
        int cur = 0;
        for (int i1 = 0; i1 < n; i1++) {
            long ugly = pq.poll();
            cur = (int) ugly;
            for (int prime : primes) {
                long u = ugly * prime;
                if (used.add(u)){
                    pq.offer(u);
                }
            }
        }
        return cur;
    }

    public static void main(String[] args) {
        HashSet<Integer> i = new HashSet<>();
        System.out.println(i.add(1));
        System.out.println(i.add(1));
        System.out.println(i.add(1));
        System.out.println(i.add(1));
    }
}
